# Name:    CProcMngr.py
# Date:    Sat Mar 27 10:42:41 CET 2010
# Purpose: Create and show about dialog
# Depends: myconst module
# Def:     CProcMngr(widget = None)
# Inputs:  

import os
import commands

####################################################################################################

class CProcMngr():
	__cmd = None

#---------------------------------------------------------------------------------------------------

	def __init__(self, command = None):
		self.__cmd = command

#---------------------------------------------------------------------------------------------------

	def getCmd(self):
		return self.__cmd

#---------------------------------------------------------------------------------------------------

	def setCmd(self, command):
		self.__cmd = command

#---------------------------------------------------------------------------------------------------
	
	def getProcStatusOutput(self):
		(status, output) = commands.getstatusoutput(self.__cmd)

		if status is not 0:
			raise CProcMngrStatusException(status)
		else:
			return (status, output)
	
#---------------------------------------------------------------------------------------------------
	
	def createProc(self, runInBackground = True):
		if runInBackground is True:
			os.system(self.__cmd + ' &')
		else:
			os.system(self.__cmd)

#---------------------------------------------------------------------------------------------------

	def execCmd(self, command, runInBackground = False):
		self.setCmd(command)
		self.createProc(runInBackground)

####################################################################################################

####################################################################################################
# CLASS EXCEPTIONS
####################################################################################################

class CProcMngrStatusException(Exception):
	__status = None

	def __init__(self, status):
		self.__status = status

	def getStatus(self):
		return self.__status

####################################################################################################
